/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

requirejs(['jquery', 'util', 'fancyBox', 'datatables', 'ztree', 'ztree_loader'], function($, util, fancyBox, dataTables, ztree, treeLoader) {
    $(function() {
        var plistPage = 0;
        var dT = $('.dTable').dataTable(DataTableConfig).api();
        $('.pd-del-btn').click(function() {
            var tR = $(this).parent().parent();
            if (confirm('你确定要删除这个产品吗')) {
                $.post(shoproot + '?/WdminAjax/deleteProduct/', {
                    id: parseInt($(this).attr('data-product-id'))
                }, function(res) {
                    if (parseInt(res) > 0) {
                        tR.fadeOut('normal', function() {
                            dT.fnDeleteRow(tR);
                        });
                    } else {
                        alert('删除失败');
                    }
                });
            }
        });

        util.scrollBottom(function() {
            if ($('.search-w-box input').val() === '') {
                util.dataTableLoading();
                $.get(shoproot + '?/WdminPage/iframe_list_product/cat=' + $('#cat').val() + '&page=' + (++plistPage) + '&part=n', function(html) {
                    var json = html.toJson();
                    if (json.count === 0) {
                        util.dataTableLoadingEnd('.dTable', true);
                    } else {
                        dT.rows.add(json.data).draw().nodes().to$().addClass('defTr font12 pdloaded' + plistPage).find('td:eq(2)').addClass('prices');
                        util.dataTableLoadingEnd('.dTable', false);
                        util.dataTableLis();
                    }
                });
            } else {
                scrolling = false;
            }
        }, 0);

    });
});